package atguigu.boot.Controller;

import atguigu.boot.bean.Cert;
import atguigu.boot.util.CommonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @program: springboot-01-helloworld
 * @ClassName HelloController
 * @description: hello接口
 * @author: zwq
 **/
@Slf4j
@RestController
public class HelloController {
    @Autowired
    private CommonUtil commonUtil;
    @Autowired
    private Cert cert;

    /**
     * 获取指定配置文件中的属性
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/getProperties")
    public String hello() throws IOException {
        log.info("【开始解析文件获取属性值】--getProperties");
        List<Map<String, Object>> list = commonUtil.getProperties("E:\\localRepositiry_gitee\\springboot-01-helloworld\\src\\main\\resources\\application-local.properties");
        String message="";
        if(list.size()>0){
            for(Map<String,Object> map:list){
                for(String key:map.keySet()){
                    String value = (String) map.get(key);
                    message+="key:"+key+"，value:"+value+"；";
                }
            }
        }
        log.info("获取的list集合：{}\n获取的最终属性：{}",list,message);
        return message;
    }

    @RequestMapping(value = "/getValue")
    public String getValue(){
        String userName = cert.getUserName();
        return userName;
    }
}
